package com.kupurui.asteacher.ui.mine.setting;

import android.os.Bundle;
import android.support.v7.widget.Toolbar;
import android.view.View;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.android.frame.util.AppManger;
import com.android.frame.view.dialog.MaterialDialog;
import com.kupurui.asteacher.R;
import com.kupurui.asteacher.bean.UserInfo;
import com.kupurui.asteacher.ui.BaseAty;
import com.kupurui.asteacher.ui.MainActivity;
import com.kupurui.asteacher.ui.login.LoginAty;
import com.kupurui.asteacher.utils.CacheUtil;
import com.kupurui.asteacher.utils.UserManger;

import java.util.Set;

import butterknife.Bind;
import butterknife.ButterKnife;
import butterknife.OnClick;
import cn.jpush.android.api.JPushInterface;
import cn.jpush.android.api.TagAliasCallback;

/**
 * 设置
 * Created by Administrator on 2017/7/17.
 */

public class SettingAty extends BaseAty {

    @Bind(R.id.tv_bar_title)
    TextView tvBarTitle;
    @Bind(R.id.m_toolbar)
    Toolbar mToolbar;
    @Bind(R.id.tv_alter_pwd)
    TextView tvAlterPwd;
    @Bind(R.id.tv_cache)
    TextView tvCache;
    @Bind(R.id.tv_cache_size)
    TextView tvCacheSize;
    @Bind(R.id.relatively_clear_cache)
    RelativeLayout relativelyClearCache;
    @Bind(R.id.tv_feed_back)
    TextView tvFeedBack;

    @Override
    public int getLayoutId() {
        return R.layout.setting_aty;
    }

    @Override
    public void initData() {
        initToolbar(mToolbar,"设置");
        try {
            tvCacheSize.setText(CacheUtil.getTotalCacheSize(this));
        }catch (Exception e){
            e.printStackTrace();
        }
    }

    @Override
    public void requestData() {

    }

    @OnClick({R.id.tv_feed_back,R.id.tv_alter_pwd,R.id.fbtn_exit_login,R.id.relatively_clear_cache})
    @Override
    public void onClick(View view) {
        super.onClick(view);
        switch (view.getId()){
            case R.id.tv_alter_pwd://修改密码
                startActivity(AlterPwdAty.class,null);
                break;
            case R.id.tv_feed_back://意见反馈
                startActivity(FeedBackAty.class,null);
                break;
            case R.id.fbtn_exit_login:
                new MaterialDialog(this).setMDTitle("提示").setMDMessage("是否要退出当前登录账号").setMDConfirmBtnClick(new MaterialDialog.DialogBtnCallBack() {
                    @Override
                    public void dialogBtnOnClick() {
                        UserManger.setUserInfo(new UserInfo());
                        UserManger.setIsLogin(false);
                        AppManger.getInstance().killActivity(MainActivity.class);
                        startActivity(LoginAty.class,null);
                        loginout();
                        finish();
                    }
                }).show();
                break;
            case R.id.relatively_clear_cache:
                new MaterialDialog(this).setMDTitle("提示").setMDMessage("是否要清理缓存信息").setMDConfirmBtnClick(new MaterialDialog.DialogBtnCallBack() {
                    @Override
                    public void dialogBtnOnClick() {
                        CacheUtil.clearAllCache(getApplicationContext());
                        tvCacheSize.setText("0B");
                        showToast("清除成功");
                    }
                }).show();
                break;
        }
    }

    private void loginout(){
        JPushInterface.setAliasAndTags(this, "", null, new TagAliasCallback() {
            @Override
            public void gotResult(int i, String s, Set<String> set) {

            }
        });

    }
}
